package com.yehuishou.service.impl;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yehuishou.dao.BidRecordDao;
import com.yehuishou.dao.BidingOrderDao;
import com.yehuishou.dao.FileDao;
import com.yehuishou.pojo.BidOrder;
import com.yehuishou.pojo.BidingOrder;
import com.yehuishou.pojo.Bidrecord;
import com.yehuishou.service.BidRecordService;

/**
 * 
 * @author ChicUniqueKing(肖洒)
 * @className
 * @data 2018年7月14日
 * @description   竞价记录
 * @Team
 * @company
 *
 */


@Service
public class BidRecordServiceImpl implements BidRecordService{
      
	
	  @Resource
	  private FileDao fileDao;
	
	  @Resource
	  private BidingOrderDao bidingOrderDao;
	
	  @Resource
	  private BidRecordDao bidRecordDao;
	

	@Override
	public List<Bidrecord> selectRecordByUid(Integer uid) {
		
		List<Bidrecord> res  = bidRecordDao.selectRecordByUid(uid);
		
		for(int i=0;i<res.size();i++) {
			
			 Bidrecord bi =res.get(i);
			String img =bi.getImg_url();
			
			if(img!=null&&img!="") {
				
				String img_url[] =img.split(";");
				if(img_url.length>1) {
					
					bi.setImg_url(fileDao.getOneImage(Integer.parseInt(img_url[1])).getFilePath());
				}
			}
			
			Integer bid =bi.getBid();
			BidOrder or = new BidOrder();
			or.setBid(bid);
			or.setUid(bi.getUid());
			//根据用户id以及竞价商品的id 查询订单
			BidOrder bidorder=bidingOrderDao.selectOneBidingOrder(or);
		
			//如果记录不为空 将它放到竞价记录中
			if(bidorder!=null) {
				bi.setBidOrder(bidorder);
			}
			
		}
		return res;
	}

  
	
	
	@Override
	public List<Bidrecord> selectRecordBybid(Bidrecord bo) {
		
		return bidRecordDao.getBidRecord(bo);
	}




	@Override
	public void insertBidRecord(Bidrecord br) {
		bidRecordDao.insertBidRecord(br);
		
	}




	@Override
	public int changeRecordStauts(Bidrecord br) {
		
		return bidRecordDao.changeRecordStauts(br);
	}
	
	
	

}
